//
//  YCTitleContentViewController.m
//  DemoTitleContentView
//
//  Created by tangkexiong on 16/3/10.
//  Copyright © 2016年 tangkexiong. All rights reserved.
//

#import "YCTitleContentViewController.h"

#import "YCTitleContentView.h"

@interface YCTitleContentViewController ()<YCTitleContentViewSource>

@end

@implementation YCTitleContentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _myView.dataSource = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - YCTitleContentViewSource

- (NSInteger)numberOfCellsInTitleContentView:(YCTitleContentView *)titleContentView {
    return 5;
}

- (void)titleContentView:(YCTitleContentView *)titleContentView cell:(YCTitleContentViewCell *)cell atIndex:(NSInteger)index {
    if (index == 0) {
        cell.titleLabel.text = @"哈哈";
    } else if (index == 1) {
        cell.titleLabel.text = @"呜呜";
    } else if (index == 2) {
        cell.titleLabel.text = @"呼呼";
    } else if (index == 3) {
        cell.titleLabel.text = @"呵呵";
    } else {
        cell.titleLabel.text = @"啦啦";
    }
    
    if (index == titleContentView.selectedIndex) {
        cell.titleLabel.textColor = [UIColor whiteColor];
    } else {
        cell.titleLabel.textColor = [UIColor blackColor];
    }
}

- (UIViewController *)titleContentView:(YCTitleContentView *)titleContentView contentVCForIndex:(NSInteger)index {
    UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"vcTest"];
    
    if (index == 0) {
        vc.view.backgroundColor = [UIColor orangeColor];
        return vc;
    } else if (index == 1) {
        vc.view.backgroundColor = [UIColor redColor];
        return vc;
    } else if (index == 2) {
        vc.view.backgroundColor = [UIColor whiteColor];
        return vc;
    } else if (index == 3) {
        vc.view.backgroundColor = [UIColor grayColor];
        return vc;
    } else {
        vc.view.backgroundColor = [UIColor blackColor];
        return vc;
    }
}

- (UIView *)selectViewInTitleContentView:(YCTitleContentView *)titleContentView {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 2)];
    view.backgroundColor = [UIColor whiteColor];
    
    return view;
}

- (CGFloat)widthOfCellInTitleContentView:(YCTitleContentView *)titleContentView {
    return titleContentView.frame.size.width * 0.3;
}

@end
